| Conditions | 6 |
| Total Lines | 41 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import type { CollectingArg } from "./ts-swiss.types" |
||
| 4 | |||
| 5 | function collector({ |
||
| 6 | identifiers, |
||
| 7 | identifierParser, |
||
| 8 | identifierMatchIndex, |
||
| 9 | identifierCleanupParser, |
||
| 10 | identifierCleanupReplace, |
||
| 11 | allowedAtRules, |
||
| 12 | }: { |
||
| 13 | identifiers: Record<string, true>, |
||
| 14 | identifierParser: RegExp, |
||
| 15 | identifierMatchIndex: number, |
||
| 16 | identifierCleanupParser: RegExp, |
||
| 17 | identifierCleanupReplace: string, |
||
| 18 | allowedAtRules: Set<string> |
||
| 19 | }) { |
||
| 20 | return ({selectors, parent}: CollectingArg) => { |
||
| 21 | if (parent?.type === "atrule") { |
||
| 22 | const {name} = parent |
||
| 23 | if (name && !allowedAtRules.has(name)) |
||
| 24 | return identifiers |
||
| 25 | } |
||
| 26 | |||
| 27 | //TODO consider postcss-selector-parser |
||
| 28 | const {length} = selectors |
||
| 29 | |||
| 30 | for (let i = length; i--; ) { |
||
| 31 | const selector = selectors[i] |
||
| 32 | |||
| 33 | let parsed: RegExpExecArray | null |
||
| 34 | |||
| 35 | // TODO check that parser is moving |
||
| 36 | while (parsed = identifierParser.exec(selector)) { |
||
| 37 | const identifier = parsed[identifierMatchIndex] |
||
| 38 | .replace(identifierCleanupParser, identifierCleanupReplace) |
||
| 39 | |||
| 40 | identifiers[identifier] = true |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | return identifiers |
||
| 45 | } |
||
| 48 |